<template>
  <div class="mod--station">
    <avue-crud
      ref="crud"
      :page="page"
      :data="dataList"
      :table-loading="dataListLoading"
      :option="tableOption"
      @search-change="searchChange"
      @on-load="getDataList"
      @refresh-change="refreshChange"
    >
      <!-- <template slot-scope="scope" slot="menuLeft">
        <el-button
          v-if="isAuth('platform:station:save')"
          icon="el-icon-plus"
          type="primary"
          size="small"
          @click="addOrUpdateHandle()"
        >新增</el-button>
      </template>-->
      <template slot-scope="scope" slot="addr">
        <span>{{scope.row.province}}{{scope.row.city}}{{scope.row.area}}{{scope.row.addr}}</span>
      </template>
      <template slot-scope="scope" slot="phone">
        <span
          v-if="scope.row.phonePrefix && scope.row.phonePrefix !== null"
        >{{scope.row.phonePrefix}}-</span>
        <span>{{scope.row.phone}}</span>
      </template>
      <template slot-scope="scope" slot="status">
        <el-tag
          v-if="scope.row.status === 4"
          size="small"
          type="info"
        >{{$t('components.auditNotPassed')}}</el-tag>
        <el-tag v-else-if="scope.row.status === 3" size="success">{{$t('liveRoom.underReview')}}</el-tag>
        <el-tag v-else-if="scope.row.status === 2" type="warning">{{$t('components.platformOffline')}}</el-tag>
        <el-tag v-else-if="scope.row.status === 1" size="small">{{$t('shop.business')}}</el-tag>
        <el-tag v-else size="small" type="danger">{{$t('seckill.close')}}</el-tag>
      </template>
      <template slot-scope="scope" slot="menu">
        <el-button
          v-if="isAuth('platform:station:update')"
          icon="el-icon-edit"
          size="small"
          type="text"
          @click="addOrUpdateHandle(scope.row.stationId)"
        >{{$t('coupon.viewDetails')}}</el-button>
        <el-button
          type="text"
          icon="el-icon-bottom"
          size="small"
          v-if="isAuth('platform:station:update') && scope.row.status<2"
          @click="offlineSeckillHandle(scope.row)"
        >{{$t('shop.offlineStation')}}</el-button>
        <el-button
          type="text"
          icon="el-icon-document-checked"
          size="small"
          v-if="isAuth('platform:station:update') && scope.row.status > 1"
          @click="stationAuditHandle(scope.row.stationId)"
        >{{scope.row.status === 2?$t('product.violation'):scope.row.status === 3?$t('coupon.checkPending'):$t('productComm.noPass')}}</el-button>
        <!-- <el-button
          v-if="isAuth('platform:station:delete')"
          type="text"
          style="color:red"
          icon="el-icon-delete"
          size="small"
          @click="deleteHandle(scope.row.stationId)"
        >删除</el-button>-->
      </template>
    </avue-crud>
    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="refreshChange"></add-or-update>
    <!-- 商品审核弹窗 -->
    <OfflineAudit
      v-if="stationAuditVisible"
      ref="offlineAudit"
      selectUrl="/platform/station/getOfflineHandleEventByStationId"
      updateUrl="/platform/station/auditStation"
      @refreshDataList="refreshChange"
    ></OfflineAudit>
  </div>
</template>

<script>
import { tableOption } from '@/crud/platform/station'
import AddOrUpdate from './station-add-or-update'
import OfflineAudit from '@/components/offline-audit'

export default {
  data () {
    return {
      dataList: [],
      page: {
        total: 0, // 总页数
        currentPage: 1, // 当前页数
        pageSize: 10 // 每页显示多少条
      },
      searchForm: {}, // 搜索
      dataListLoading: false,
      tableOption: tableOption,
      addOrUpdateVisible: false,
      stationAuditVisible: false
    }
  },
  components: {
    AddOrUpdate,
    OfflineAudit
  },
  created () {
  },
  mounted () {
  },
  methods: {
    getDataList (page) {
      this.dataListLoading = true
      this.$http({
        url: this.$http.adornUrl('/platform/station/page'),
        method: 'get',
        params: this.$http.adornParams(
          Object.assign(
            {
              current: page == null ? this.page.currentPage : page.currentPage,
              size: page == null ? this.page.pageSize : page.pageSize
            },
            this.searchForm
          )
        )
      }).then(({ data }) => {
        this.dataList = data.records
        this.page.total = data.total
        this.dataListLoading = false
      })
    },
    // 新增 / 修改
    addOrUpdateHandle (id) {
      this.addOrUpdateVisible = true
      this.$nextTick(() => {
        this.$refs.addOrUpdate.init(id)
      })
    },
    // deleteHandle (id) {
    //   this.$confirm('确定进行删除操作?', '提示', {
    //     confirmButtonText: '确定',
    //     cancelButtonText: '取消',
    //     type: 'warning'
    //   }).then(() => {
    //     this.$http({
    //       url: this.$http.adornUrl('/platform/station/' + id),
    //       method: 'delete',
    //       data: this.$http.adornData({})
    //     }).then(({ data }) => {
    //       this.$message({
    //         message: '操作成功',
    //         type: 'success',
    //         duration: 1500,
    //         onClose: () => {
    //           this.refreshChange()
    //         }
    //       })
    //     })
    //   }).catch(() => { })
    // },
    // 下线活动
    offlineSeckillHandle (row) {
      // '确定对活动[' + row.stationName + ']进行下线操作？如是，请填写下线理由'
      var tips = this.$i18n.t('seckill.stationOfflineTip')
      tips = tips.replace('STATIONNAME', row.stationName)
      this.$prompt(tips, this.$i18n.t('text.tips'), {
        confirmButtonText: this.$i18n.t('coupon.confirm'),
        cancelButtonText: this.$i18n.t('coupon.cancel')
      }).then((obj) => {
        if (!obj.value) {
          this.$message.error(this.$i18n.t('seckill.offlineReasonTip'))
          return
        }
        this.$http({
          url: this.$http.adornUrl(`/platform/station/offline`),
          method: 'post',
          data: this.$http.adornData({
            handleId: row.stationId,
            offlineReason: obj.value || null
          })
        }).then(({ data }) => {
          this.$message({
            message: this.$i18n.t('publics.operation'),
            type: 'success',
            duration: 1500,
            onClose: () => {
              this.getDataList(this.page)
            }
          })
        })
      })
    },
    // 弹窗处理
    stationAuditHandle (id) {
      this.stationAuditVisible = true
      this.$nextTick(() => {
        this.$refs.offlineAudit.init(id)
      })
    },
    /**
     * 刷新回调
     */
    refreshChange () {
      this.page = this.$refs.crud.$refs.tablePage.defaultPage
      this.getDataList(this.page)
    },
    searchChange (params) {
      this.searchForm = params
      this.getDataList(this.page)
    }
  }
}
</script>
<style lang="scss">
.mod--station {
}
</style>
